package main

import (
	"fmt"
	"os"
	"path/filepath"
	"strings"

	"github.com/micro-plat/lib4go/db"
)

/* 运行方式:
* ./ddscli oracle microplat_dds_test/123456@orcl136
* ./ddscli mysql 'root:rTo0CesHi2018Qx@tcp(192.168.0.36:3306)/dds_test?charset=utf8'
 */
func main() {
	if len(os.Args) != 3 {
		fmt.Println("传入参数有误,格式为: ./ddscli oracle microplat_dds/123456@orcl136")
		return
	}

	if !strings.EqualFold(os.Args[1], "oracle") && !strings.EqualFold(os.Args[1], "mysql") {
		fmt.Println("provider传入有误,只支持oracle/mysql")
		return
	}

	//创建相关表
	dbe, err := db.NewDB(os.Args[1], os.Args[2], 20, 10, 600)
	if err != nil {
		fmt.Printf("构建数据链接对象失败,err:%+v", err)
		return
	}

	dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
	if err := db.CreateDB(dbe, fmt.Sprintf("%s/sql/%s", dir, os.Args[1])); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("数据表创建成功")
}
